package org.example.utils;

import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.ShiroUtils;

import java.util.Arrays;
import java.util.List;

public class Util {

    /**
     * 合同类型采购
     */
    public static final String CONTRACT_TYPE_BUY="0";

    /**
     * 合同类型销售
     */
    public static final String CONTRACT_TYPE_SELL="1";

    /**
     * 密码
     */
    public static final String PASSWORD="123456";

    /**
     * 供应商角色
     */
    public static final Long SUPPLIER_ROLE=106L;






    /**
     * 是否是供应商
     * @return
     */
    public static boolean isGongYingShangRole(){
        boolean flag=false;
        List<SysRole> list = ShiroUtils.getSysUser().getRoles();
        for(SysRole role:list){
            if(role.getRoleId().equals(106L)){
                flag= true ;break;
            }
        }
        return flag;
    }

    /**
     * 是否是租户
     * @return
     */
    public static boolean isZuHuRole(){
        boolean flag=false;
        List<SysRole> list = ShiroUtils.getSysUser().getRoles();
        for(SysRole role:list){
            if(role.getRoleId().equals(100L)){
                flag= true ;break;
            }
        }
        return flag;
    }

    /**
     * 查询自己数据
     * @return
     */
    public static void setQuerySelfData(BaseEntity entity){
        boolean flag=false;
        List<SysRole> list = ShiroUtils.getSysUser().getRoles();
        for(SysRole role:list){
            if("SalesUser".equals(role.getRoleKey())){//销售
                entity.setCreateBy(ShiroUtils.getUserId()+""); break;
            }else if("ProcurementUser".equals(role.getRoleKey())){//采购
                entity.setCreateBy(ShiroUtils.getUserId()+"");break;
            }
        }
    }


}
